package com.smit.livevideo.sample.view;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.smit.livevideo.R;

/**
 * Created by smfang on 2015/12/28.
 * CI MMI Menu的容器
 */
public class CIListAdapter extends ArrayAdapter<CIListItem>
{

    int resourceId;

    /**
     * CIListAdapter构造函数
     * @param context Context对象
     * @param textViewResourceId 显示的文本ID
     * @param objects 显示的对象
     */
    public CIListAdapter(Context context, int textViewResourceId, List<CIListItem> objects)
    {
        super(context, textViewResourceId, objects);
        resourceId = textViewResourceId;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        CIListItem item = getItem(position);

        View view = null;
        if (convertView == null)
        {
            view = LayoutInflater.from(getContext()).inflate(resourceId, null);
            holder = new ViewHolder();
            holder.ciItemText = (TextView) view.findViewById(R.id.ciItemText);
            view.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.ciItemText.setText(item.ciName);
        return view;
    }

    private static class ViewHolder
    {
        TextView ciItemText;
    }

}
